package com.itheima.servlet;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


import com.google.gson.Gson;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

public class JsonTest {
	public static void main(String[] args) {
		t1();
		System.out.println("===");
		t2();
		System.out.println("===");
		t3();
	}
	public static void t1(){
		String[] x = {"aa","bb","cc"};
		JSONArray fromObject = JSONArray.fromObject(x);
		System.out.println(fromObject);
	}
	public static void t2(){
		List<String> list = new ArrayList<>();
		list.add("xx");
		list.add("yy");
		list.add("zz");
		
		JSONArray fromObject = JSONArray.fromObject(list);
		System.out.println(fromObject);
	}
	
	public static void t3(){
		Map<String, String> map = new HashMap<>();
		map.put("ii", "II");
		map.put("jj", "JJ");
		map.put("qq", "QQ");
		map.put("kk", "KK");
		
		/*JSONObject map1 = JSONObject.fromObject(map);
		System.out.println(map1);*/
		
		Gson g = new Gson();
		String json = g.toJson(map);
		System.out.println(json);
	}
	
	public void t4(){
		User user = new User("zhangsan", "123");
		
		JSONObject fromObject = JSONObject.fromObject(user);
		System.out.println(fromObject);
	}
}
